module.exports = function (app, models, $, db, nm) {
	//获取群组列表
	app.get('/v1/group',(req,res) => {
		var query = {
			pageSize:req.query.pageSize || 10,
			pageNum:req.query.pageNum || 1,
			unitId:req.unitId
		}
		if(req.query.name) query.name = {$regex:req.query.name}
		models.group.list(query, ret => {
			res.send(ret)
		},{
			projection: {
				name: 1,
				_id:1,
				desoptions:1,
				status:1
			}
		})
	})
	//新增群组信息
	app.post('/v1/group',(req,res) => {
		req.body.unitId = req.unitId
		models.group.insert(req.body, ret => {
			res.send(ret)
		})
	})
	//修改群组信息
	app.put('/v1/group',(req,res) => {
		models.group.update({_id:req.body._id},req.body, ret => {
			res.send(ret)
		})
	})
	//获取群组详情
	app.get('/v1/groupInfo',(req,res) => {
		if(req.query._id){
			models.group.find({_id:req.query._id}, ret => {
				res.send(ret)
			},{
				projection: {
					name: 1,
					_id:1,
					desoptions:1,
					status:1
				}
			})
		}else{
			res.send({errorMsg:'请传入_id'})
		}
	})
	//新增群组菜单
	app.post('/v1/groupMenu',(req,res) => {
		models.group_menu.insert({ groupId:req.body.groupId, menuId:req.body.menuId, unitId: req.unitId }, ret => {
			res.send(ret)
		})
	})
	//删除群组菜单
	app.delete('/v1/groupMenu',(req,res) => {
		models.group_menu.remove({groupId:req.query.groupId,menuId:req.query.menuId,unitId:req.unitId}, ret => {
			res.send(ret)
		},{real:true})
	})
}